** Initial data setup for Generations and Gender Programme (GGP) surveys

cap log close
clear all
set more off

global cnt "BGR RUS GEO DEU FRA HUN ITA NLD ROU NOR AUT EST BEL AUS LTU POL CZE SWE"

foreach c of global cnt {
cd /*insert your working directory here*/

use GGS_Wave1_`c'.dta

keep a5106a_s a5106a_b a5106a_1601 a5106a_2400 acountry aage abyear ayear asex a148 a5113 a5115


** 1 Year & country **

rename ayear year


ge country=.
lab var country "country iso code"

replace country=100 if acountry==11
replace country=643 if acountry==12
replace country=268 if acountry==13
replace country=276 if acountry==14
replace country=250 if acountry==15
replace country=348 if acountry==16
replace country=380 if acountry==17
replace country=528 if acountry==18
replace country=642 if acountry==19
replace country=578 if acountry==20
replace country=40 if acountry==21
replace country=233 if acountry==22
replace country=56 if acountry==23
replace country=36 if acountry==24
replace country=440 if acountry==25
replace country=616 if acountry==26
replace country=203 if acountry==28
replace country=752 if acountry==29

#delimit ;
lab def country
36 "Australia"
40 "Austria"
56 "Belgium"
100 "Bulgaria"
203 "Czech Rep"
233 "Estonia"
250 "France"
268 "Georgia"
276 "Germany"
348 "Hungary"
380 "Italy"
440 "Lithuania"
528 "Netherlands"
578 "Norway"
616 "Poland"
642 "Romania"
643 "Russia"
752 "Sweden";
lab val country country;
#delimit cr 


drop acountry

** 2 Identification var **

ge pid=_n
lab var pid "Personal ID"

** 3 Birth Year & Age & Sex **

rename aage age
rename abyear birthyr
rename asex sex

** 4 Siblings **
// all countries but Australia & Hungary: numbers of brothers and sisters
// Australia & Hungary: total number of siblings

rename a5106a_s nsis
rename a5106a_b nbro

ge nsibs = nsis + nbro if country!=36 | country!=348

replace nsibs = a5106a_2400 if country==36  // Australia
replace nsibs = a5106a_1601 if country==348  // Hungary

lab var nsibs "total number of siblings"
drop a5106a_2400 a5106a_1601

** 5 Own & Parental Education **

rename a148 educ
rename a5113 faeduc
rename a5115 maeduc

ge educ_yrs=.
ge faeduc_yrs=.
ge maeduc_yrs=.

ge educ_isced=.
ge faeduc_isced=.
ge maeduc_isced=.

foreach v of varlist educ faeduc maeduc {

// Australia
if country==36 { 
replace `v'_yrs=1  if `v'==0
replace `v'_yrs=8.5  if `v'==1
replace `v'_yrs=10.5  if `v'==2
replace `v'_yrs=12.5  if `v'==3
replace `v'_yrs=15.5  if `v'==4
replace `v'_yrs=17.5  if `v'==5
replace `v'_yrs=20  if `v'==6

replace `v'_yrs=17.5  if `v'==2401 // university degree
replace `v'_yrs=17.5  if `v'==2402 // teachers college, advanced education
replace `v'_yrs=17.5  if `v'==2403 // institute of technology
replace `v'_yrs=16.5  if `v'==2404 // tech college
replace `v'_yrs=15.5  if `v'==2405 // employer provided education
replace `v'_yrs=10.5  if `v'==2406 // other
}


// Austria
if country==40 {
replace `v'_yrs=0  if `v'==0
replace `v'_yrs=4  if `v'==1
replace `v'_yrs=9  if `v'==2
replace `v'_yrs=13  if `v'==3
replace `v'_yrs=15  if `v'==4
replace `v'_yrs=17  if `v'==5
replace `v'_yrs=20  if `v'==6
}


// Belgium
if country==56 {
replace `v'_yrs=0  if `v'==0
replace `v'_yrs=6  if `v'==1
replace `v'_yrs=9  if `v'==2
replace `v'_yrs=13  if `v'==3
replace `v'_yrs=15  if `v'==4
replace `v'_yrs=17  if `v'==5
replace `v'_yrs=20  if `v'==6
}


// Bulgaria
if country==100 {
replace `v'_yrs=0  if `v'==0
replace `v'_yrs=4  if `v'==1
replace `v'_yrs=8  if `v'==2
replace `v'_yrs=12  if `v'==3
replace `v'_yrs=15  if `v'==4
replace `v'_yrs=17.5  if `v'==5
replace `v'_yrs=20  if `v'==6
replace `v'_yrs=0  if `v'==1101  // no schooling, illiterate
}


// Czech Rep
if country==203 {
replace `v'_yrs=0  if `v'==0
replace `v'_yrs=5  if `v'==1
replace `v'_yrs=9  if `v'==2
replace `v'_yrs=13  if `v'==3
replace `v'_yrs=16  if `v'==4
replace `v'_yrs=16  if `v'==5
replace `v'_yrs=20  if `v'==6
}

// Estonia
if country==233 {
replace `v'_yrs=0  if `v'==0
replace `v'_yrs=6  if `v'==1
replace `v'_yrs=9  if `v'==2
replace `v'_yrs=12  if `v'==3
replace `v'_yrs=15  if `v'==4
replace `v'_yrs=17  if `v'==5
replace `v'_yrs=20  if `v'==6
}

// France
if country==250 {
replace `v'_yrs=0  if `v'==1501  // 0
replace `v'_yrs=9  if `v'==1502  // 1-2
replace `v'_yrs=12  if `v'==1503  // 3A
replace `v'_yrs=12  if `v'==1504  // 3B
replace `v'_yrs=12  if `v'==1505  // 3C
replace `v'_yrs=15  if `v'==1506  // 5A-6
replace `v'_yrs=14  if `v'==1507  // 5B
}

// Georgia
if country==268 {
replace `v'_yrs=0  if `v'==0
replace `v'_yrs=6  if `v'==1
replace `v'_yrs=9  if `v'==2
replace `v'_yrs=12  if `v'==3
replace `v'_yrs=14  if `v'==4
replace `v'_yrs=16  if `v'==5
replace `v'_yrs=20  if `v'==6
}

// Germany
if country==276 {
replace `v'_yrs=0  if `v'==0
replace `v'_yrs=4  if `v'==1
replace `v'_yrs=10  if `v'==2
replace `v'_yrs=13  if `v'==3
replace `v'_yrs=15  if `v'==4
replace `v'_yrs=18  if `v'==5
replace `v'_yrs=20  if `v'==6
}

// Hungary
if country==348 {
replace `v'_yrs=0  if `v'==0
replace `v'_yrs=4  if `v'==1
replace `v'_yrs=8  if `v'==2
replace `v'_yrs=12  if `v'==3
replace `v'_yrs=13.5  if `v'==4
replace `v'_yrs=16.5  if `v'==5
replace `v'_yrs=20  if `v'==6
}

// Italy
if country==380 {
replace `v'_yrs=0  if `v'==0
replace `v'_yrs=5  if `v'==1
replace `v'_yrs=8  if `v'==2
replace `v'_yrs=13  if `v'==3
replace `v'_yrs=17  if `v'==1701  // 5A,6
replace `v'_yrs=16  if `v'==1702  // 5A
replace `v'_yrs=16  if `v'==1703  // 5A-5B
}

// Lithuania
if country==440 {
replace `v'_yrs=0  if `v'==0
replace `v'_yrs=3  if `v'==1
replace `v'_yrs=8  if `v'==2
replace `v'_yrs=11  if `v'==3
replace `v'_yrs=15  if `v'==4
replace `v'_yrs=16  if `v'==5
replace `v'_yrs=20  if `v'==6
}

// Netherlands
if country==528 {
replace `v'_yrs=0  if `v'==0
replace `v'_yrs=6  if `v'==1
replace `v'_yrs=10  if `v'==2
replace `v'_yrs=12  if `v'==3
replace `v'_yrs=15  if `v'==4
replace `v'_yrs=16  if `v'==5
replace `v'_yrs=20  if `v'==6
}

// Norway
if country==578 {
replace `v'_yrs=0  if `v'==0
replace `v'_yrs=6  if `v'==1
replace `v'_yrs=9  if `v'==2
replace `v'_yrs=12  if `v'==3
replace `v'_yrs=14  if `v'==4
replace `v'_yrs=16  if `v'==5
replace `v'_yrs=20  if `v'==6

replace `v'_yrs=6  if `v'==2001  // primary (parents only)
replace `v'_yrs=12  if `v'==2002  // secondary (parents only)
replace `v'_yrs=16  if `v'==2003  // tertiary (parents only)
}

// Poland
if country==616 {
replace `v'_yrs=0  if `v'==0
replace `v'_yrs=6  if `v'==1
replace `v'_yrs=8  if `v'==2
replace `v'_yrs=12  if `v'==3
replace `v'_yrs=15  if `v'==4
replace `v'_yrs=16  if `v'==5
replace `v'_yrs=20  if `v'==6
}

// Romania
if country==642 {
replace `v'_yrs=0  if `v'==0
replace `v'_yrs=4  if `v'==1
replace `v'_yrs=8  if `v'==2
replace `v'_yrs=12.5  if `v'==3
replace `v'_yrs=14  if `v'==4
replace `v'_yrs=16  if `v'==5
replace `v'_yrs=20  if `v'==6
}

// Russia
if country==643 {
replace `v'_yrs=0  if `v'==0
replace `v'_yrs=4  if `v'==1
replace `v'_yrs=9  if `v'==2
replace `v'_yrs=12  if `v'==3
replace `v'_yrs=13  if `v'==4
replace `v'_yrs=15 if `v'==5
replace `v'_yrs=20  if `v'==6
}

// Sweden
if country==752 {
replace `v'_yrs=0  if `v'==0
replace `v'_yrs=6  if `v'==1
replace `v'_yrs=9  if `v'==2
replace `v'_yrs=12  if `v'==3
replace `v'_yrs=14  if `v'==4
replace `v'_yrs=16  if `v'==5
replace `v'_yrs=20  if `v'==6

replace `v'_yrs=12  if `v'==2901  // isced 2 & 3 (parents only)
replace `v'_yrs=16  if `v'==2902  // post-secondary (isced 4,5,6) (parents only)
}

replace `v'_isced=20  if `v'==0
replace `v'_isced=100  if `v'==1
replace `v'_isced=200  if `v'==2
replace `v'_isced=300  if `v'==3
replace `v'_isced=400  if `v'==4
replace `v'_isced=600  if `v'==5
replace `v'_isced=700  if `v'==6

* Australia
replace `v'_isced=665  if `v'==2401 // university degree
replace `v'_isced=665  if `v'==2402 // teachers college, advanced education
replace `v'_isced=665  if `v'==2403 // institute of technology
replace `v'_isced=554  if `v'==2404 // tech college
replace `v'_isced=453 if `v'==2405 // employer provided education
replace `v'_isced=.  if `v'==2406 // other

* Bulgaria
replace `v'_isced=0  if `v'==1101

* France
replace `v'_isced=20  if `v'==1501  // 0
replace `v'_isced=244  if `v'==1502  // 1-2
replace `v'_isced=344  if `v'==1503  // 3A
replace `v'_isced=354  if `v'==1504  // 3B
replace `v'_isced=353  if `v'==1505  // 3C
replace `v'_isced=700  if `v'==1506  // 5A-6
replace `v'_isced=554  if `v'==1507  // 5B

* Italy
replace `v'_isced=700  if `v'==1701  // 5A,6
replace `v'_isced=655  if `v'==1702  // 5A
replace `v'_isced=554  if `v'==1703  // 5A-5B

* Norway
replace `v'_isced=100  if `v'==2001  // primary (parents only)
replace `v'_isced=300  if `v'==2002  // secondary (parents only)
replace `v'_isced=600  if `v'==2003  // tertiary (parents only)

* Sweden
replace `v'_isced=300  if `v'==2901  // isced 2 & 3 (parents only)
replace `v'_isced=600  if `v'==2902  // post-secondary (isced 4,5,6) (parents only)

}

** 6 Save **

qui sum year
local y=r(min)

cd /*insert your working directory here*/
saveold `c'`y',replace
}

***OPTIONAL MODIFICATION TO GERMAN FILE TO SPLIT BY EAST AND WEST***

***Add region variable back to Germany - split to East and West***

**create East/West indicator from raw file**
cd /*insert your working directory here*/

use GGS_Wave1_DEU.dta

keep aregion

ge pid=_n

ge east = .
replace east = 1 if aregion > 1411 & aregion < .
replace east = 0 if aregion < 1411 & aregion < .

ge berlin_flag = 0
replace berlin_flag = 1 if aregion == 1411

drop aregion


saveold GGS_Wave1_DEU_region.dta, replace

**Merge region file to main DEU file**

use GGS_Wave1_DEU.dta

sort pid

merge 1:1 pid using GGS_Wave1_DEU_region.dta

drop _merge

save GGS_Wave1_DEU.dta, replace

**save East German File***

use GGS_Wave1_DEU.dta

drop if east == 0

*drop Berlin cases*

drop if berlin_flag == 1

drop east berlin_flag

replace country = 278
lab def country_lab 278 "East Germany"
lab val country country_lab

save GGS_Wave1_EDEU.dta, replace

**save West German File***

use GGS_Wave1_DEU.dta

drop if east == 1

*drop Berlin cases*

drop if berlin_flag == 1

drop east berlin_flag

replace country = 280
lab def country_lab 280 "West Germany"
lab val country country_lab

save GGS_Wave1_WDEU.dta, replace


















